mcurrentsens 2.2.0
Loading...
Searching...
No Matches
mcurrentsens.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2026 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
27
28#ifndef MCURRENTSENS_H
29#define MCURRENTSENS_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_spi_master.h"
52#include "spi_specifics.h"
53#include "drv_i2c_master.h"
54
60
65
70
75#define MCURRENTSENS_REG_ADCDATA 0x00
76#define MCURRENTSENS_REG_CONFIG0 0x01
77#define MCURRENTSENS_REG_CONFIG1 0x02
78#define MCURRENTSENS_REG_CONFIG2 0x03
79#define MCURRENTSENS_REG_CONFIG3 0x04
80#define MCURRENTSENS_REG_IRQ 0x05
81#define MCURRENTSENS_REG_MUX 0x06
82#define MCURRENTSENS_REG_SCAN 0x07
83#define MCURRENTSENS_REG_TIMER 0x08
84#define MCURRENTSENS_REG_OFFSETCAL 0x09
85#define MCURRENTSENS_REG_GAINCAL 0x0A
86#define MCURRENTSENS_REG_RESERVED_24 0x0B
87#define MCURRENTSENS_REG_RESERVED_8 0x0C
88#define MCURRENTSENS_REG_LOCK 0x0D
89#define MCURRENTSENS_REG_RESERVED_16 0x0E
90#define MCURRENTSENS_REG_CRCCFG 0x0F
91
96#define MCURRENTSENS_CMD_DEV_ADDR 0x40
97#define MCURRENTSENS_CMD_DEV_ADDR_MASK 0xC0
98#define MCURRENTSENS_CMD_REG_ADDR_SHIFT 2
99#define MCURRENTSENS_CMD_REG_ADDR_MASK 0x3C
100#define MCURRENTSENS_CMD_TYPE_STATIC_READ 0x01
101#define MCURRENTSENS_CMD_TYPE_INC_WRITE 0x02
102#define MCURRENTSENS_CMD_TYPE_INC_READ 0x03
103#define MCURRENTSENS_CMD_TYPE_MASK 0x03
104#define MCURRENTSENS_FAST_CMD_CONV_START ( 0x28 | MCURRENTSENS_CMD_DEV_ADDR )
105#define MCURRENTSENS_FAST_CMD_STANDBY ( 0x2C | MCURRENTSENS_CMD_DEV_ADDR )
106#define MCURRENTSENS_FAST_CMD_SHUTDOWN ( 0x30 | MCURRENTSENS_CMD_DEV_ADDR )
107#define MCURRENTSENS_FAST_CMD_FULL_SHUTDOWN ( 0x34 | MCURRENTSENS_CMD_DEV_ADDR )
108#define MCURRENTSENS_FAST_CMD_FULL_RESET ( 0x38 | MCURRENTSENS_CMD_DEV_ADDR )
109 // mcurrentsens_reg
111
116
121
126#define MCURRENTSENS_CONFIG0_VREF_SEL_EXT 0x00
127#define MCURRENTSENS_CONFIG0_VREF_SEL_INT 0x80
128#define MCURRENTSENS_CONFIG0_VREF_SEL_MASK 0x80
129#define MCURRENTSENS_CONFIG0_PARTIAL_SHUTDOWN_EN 0x00
130#define MCURRENTSENS_CONFIG0_PARTIAL_SHUTDOWN_DIS 0x40
131#define MCURRENTSENS_CONFIG0_PARTIAL_SHUTDOWN_MASK 0x40
132#define MCURRENTSENS_CONFIG0_CLK_SEL_EXT 0x00
133#define MCURRENTSENS_CONFIG0_CLK_SEL_INT_NO_OUT 0x20
134#define MCURRENTSENS_CONFIG0_CLK_SEL_INT_OUT 0x30
135#define MCURRENTSENS_CONFIG0_CLK_SEL_MASK 0x30
136#define MCURRENTSENS_CONFIG0_CS_SEL_NONE 0x00
137#define MCURRENTSENS_CONFIG0_CS_SEL_0P9UA 0x04
138#define MCURRENTSENS_CONFIG0_CS_SEL_3P7UA 0x08
139#define MCURRENTSENS_CONFIG0_CS_SEL_15UA 0x0C
140#define MCURRENTSENS_CONFIG0_CS_SEL_MASK 0x0C
141#define MCURRENTSENS_CONFIG0_ADC_MODE_SHUTDOWN 0x00
142#define MCURRENTSENS_CONFIG0_ADC_MODE_STANDBY 0x02
143#define MCURRENTSENS_CONFIG0_ADC_MODE_CONVERSION 0x03
144#define MCURRENTSENS_CONFIG0_ADC_MODE_MASK 0x03
145
150#define MCURRENTSENS_CONFIG1_PRE_DIV_1 0x00
151#define MCURRENTSENS_CONFIG1_PRE_DIV_2 0x40
152#define MCURRENTSENS_CONFIG1_PRE_DIV_4 0x80
153#define MCURRENTSENS_CONFIG1_PRE_DIV_8 0xC0
154#define MCURRENTSENS_CONFIG1_PRE_DIV_MASK 0xC0
155#define MCURRENTSENS_CONFIG1_OSR_32 0x00
156#define MCURRENTSENS_CONFIG1_OSR_64 0x04
157#define MCURRENTSENS_CONFIG1_OSR_128 0x08
158#define MCURRENTSENS_CONFIG1_OSR_256 0x0C
159#define MCURRENTSENS_CONFIG1_OSR_512 0x10
160#define MCURRENTSENS_CONFIG1_OSR_1024 0x14
161#define MCURRENTSENS_CONFIG1_OSR_2048 0x18
162#define MCURRENTSENS_CONFIG1_OSR_4096 0x1C
163#define MCURRENTSENS_CONFIG1_OSR_8192 0x20
164#define MCURRENTSENS_CONFIG1_OSR_16384 0x24
165#define MCURRENTSENS_CONFIG1_OSR_20480 0x28
166#define MCURRENTSENS_CONFIG1_OSR_24576 0x2C
167#define MCURRENTSENS_CONFIG1_OSR_40960 0x30
168#define MCURRENTSENS_CONFIG1_OSR_49152 0x34
169#define MCURRENTSENS_CONFIG1_OSR_81920 0x38
170#define MCURRENTSENS_CONFIG1_OSR_98304 0x3C
171#define MCURRENTSENS_CONFIG1_OSR_MASK 0x3C
172
177#define MCURRENTSENS_CONFIG2_BOOST_X0P5 0x00
178#define MCURRENTSENS_CONFIG2_BOOST_X0P66 0x40
179#define MCURRENTSENS_CONFIG2_BOOST_X1 0x80
180#define MCURRENTSENS_CONFIG2_BOOST_X2 0xC0
181#define MCURRENTSENS_CONFIG2_BOOST_MASK 0xC0
182#define MCURRENTSENS_CONFIG2_GAIN_X0P33 0x00
183#define MCURRENTSENS_CONFIG2_GAIN_X1 0x08
184#define MCURRENTSENS_CONFIG2_GAIN_X2 0x10
185#define MCURRENTSENS_CONFIG2_GAIN_X4 0x18
186#define MCURRENTSENS_CONFIG2_GAIN_X8 0x20
187#define MCURRENTSENS_CONFIG2_GAIN_X16 0x28
188#define MCURRENTSENS_CONFIG2_GAIN_X32 0x30
189#define MCURRENTSENS_CONFIG2_GAIN_X64 0x38
190#define MCURRENTSENS_CONFIG2_GAIN_MASK 0x38
191#define MCURRENTSENS_CONFIG2_AZ_MUX_DIS 0x00
192#define MCURRENTSENS_CONFIG2_AZ_MUX_EN 0x04
193#define MCURRENTSENS_CONFIG2_AZ_MUX_MASK 0x04
194#define MCURRENTSENS_CONFIG2_AZ_REF_DIS 0x00
195#define MCURRENTSENS_CONFIG2_AZ_REF_EN 0x02
196#define MCURRENTSENS_CONFIG2_AZ_REF_MASK 0x02
197#define MCURRENTSENS_CONFIG2_RESERVED 0x01
198
203#define MCURRENTSENS_CONFIG3_CONV_MODE_ONE_SHOT_SHUT 0x00
204#define MCURRENTSENS_CONFIG3_CONV_MODE_ONE_SHOT_STBY 0x80
205#define MCURRENTSENS_CONFIG3_CONV_MODE_CONTINUOUS 0xC0
206#define MCURRENTSENS_CONFIG3_CONV_MODE_MASK 0xC0
207#define MCURRENTSENS_CONFIG3_DATA_FORMAT_24BIT 0x00
208#define MCURRENTSENS_CONFIG3_DATA_FORMAT_32BIT_LEFT 0x10
209#define MCURRENTSENS_CONFIG3_DATA_FORMAT_32BIT_RIGHT 0x20
210#define MCURRENTSENS_CONFIG3_DATA_FORMAT_32BIT_CHID 0x30
211#define MCURRENTSENS_CONFIG3_DATA_FORMAT_MASK 0x30
212#define MCURRENTSENS_CONFIG3_CRC_FORMAT_16BIT 0x00
213#define MCURRENTSENS_CONFIG3_CRC_FORMAT_32BIT 0x08
214#define MCURRENTSENS_CONFIG3_CRC_FORMAT_MASK 0x08
215#define MCURRENTSENS_CONFIG3_EN_CRCCOM_DIS 0x00
216#define MCURRENTSENS_CONFIG3_EN_CRCCOM_EN 0x04
217#define MCURRENTSENS_CONFIG3_EN_CRCCOM_MASK 0x04
218#define MCURRENTSENS_CONFIG3_EN_OFFCAL_DIS 0x00
219#define MCURRENTSENS_CONFIG3_EN_OFFCAL_EN 0x02
220#define MCURRENTSENS_CONFIG3_EN_OFFCAL_MASK 0x02
221#define MCURRENTSENS_CONFIG3_EN_GAINCAL_DIS 0x00
222#define MCURRENTSENS_CONFIG3_EN_GAINCAL_EN 0x01
223#define MCURRENTSENS_CONFIG3_EN_GAINCAL_MASK 0x01
224
229#define MCURRENTSENS_IRQ_DR_STATUS 0x40
230#define MCURRENTSENS_IRQ_CRCCFG_STATUS 0x20
231#define MCURRENTSENS_IRQ_POR_STATUS 0x10
232#define MCURRENTSENS_IRQ_MODE_IRQ_HIGH_Z 0x00
233#define MCURRENTSENS_IRQ_MODE_IRQ_LOGIC_HIGH 0x04
234#define MCURRENTSENS_IRQ_MODE_MDAT_HIGH_Z 0x08
235#define MCURRENTSENS_IRQ_MODE_MDAT_LOGIC_HIGH 0x0C
236#define MCURRENTSENS_IRQ_MODE_MASK 0x0C
237#define MCURRENTSENS_IRQ_EN_FASTCMD_DIS 0x00
238#define MCURRENTSENS_IRQ_EN_FASTCMD_EN 0x02
239#define MCURRENTSENS_IRQ_EN_FASTCMD_MASK 0x02
240#define MCURRENTSENS_IRQ_EN_STP_DIS 0x00
241#define MCURRENTSENS_IRQ_EN_STP_EN 0x01
242#define MCURRENTSENS_IRQ_EN_STP_MASK 0x01
243
248#define MCURRENTSENS_MUX_VIN_P_SHIFT 4
249#define MCURRENTSENS_MUX_VIN_P_MASK 0xF0
250#define MCURRENTSENS_MUX_VIN_N_SHIFT 0
251#define MCURRENTSENS_MUX_VIN_N_MASK 0x0F
252#define MCURRENTSENS_MUX_CH0 0x00
253#define MCURRENTSENS_MUX_CH1 0x01
254#define MCURRENTSENS_MUX_CH2 0x02
255#define MCURRENTSENS_MUX_CH3 0x03
256#define MCURRENTSENS_MUX_CH4 0x04
257#define MCURRENTSENS_MUX_CH5 0x05
258#define MCURRENTSENS_MUX_CH6 0x06
259#define MCURRENTSENS_MUX_CH7 0x07
260#define MCURRENTSENS_MUX_AGND 0x08
261#define MCURRENTSENS_MUX_AVDD 0x09
262#define MCURRENTSENS_MUX_RESERVED 0x0A
263#define MCURRENTSENS_MUX_REFIN_OUT 0x0B
264#define MCURRENTSENS_MUX_REFIN_IN 0x0C
265#define MCURRENTSENS_MUX_TEMP_P 0x0D
266#define MCURRENTSENS_MUX_TEMP_M 0x0E
267#define MCURRENTSENS_MUX_VCM 0x0F
268
273#define MCURRENTSENS_MUX_CH1_CURRENT_P MCURRENTSENS_MUX_CH0
274#define MCURRENTSENS_MUX_CH1_CURRENT_N MCURRENTSENS_MUX_CH1
275#define MCURRENTSENS_MUX_CH1_VOLTAGE_P MCURRENTSENS_MUX_CH2
276#define MCURRENTSENS_MUX_CH1_VOLTAGE_N MCURRENTSENS_MUX_CH3
277#define MCURRENTSENS_MUX_CH2_VOLTAGE_P MCURRENTSENS_MUX_CH4
278#define MCURRENTSENS_MUX_CH2_VOLTAGE_N MCURRENTSENS_MUX_CH5
279#define MCURRENTSENS_MUX_CH2_CURRENT_P MCURRENTSENS_MUX_CH6
280#define MCURRENTSENS_MUX_CH2_CURRENT_N MCURRENTSENS_MUX_CH7
281
286#define MCURRENTSENS_RESERVED_24_DEFAULT 0x900000ul
287#define MCURRENTSENS_RESERVED_8_DEFAULT 0x30
288#define MCURRENTSENS_RESERVED_16_DEFAULT 0x000F
289
294#define MCURRENTSENS_OFFSETCAL_DEFAULT 0x000000ul
295#define MCURRENTSENS_GAINCAL_DEFAULT 0x800000ul
296
301#define MCURRENTSENS_LOCK_UNLOCK 0xA5
302#define MCURRENTSENS_LOCK_LOCK 0x00
303
308#define MCURRENTSENS_CH1_GAIN_OPAMP 50.0f
309#define MCURRENTSENS_CH1_R5_RSHUNT 0.05f
310#define MCURRENTSENS_CH1_CURRENT_COEFF ( MCURRENTSENS_CH1_GAIN_OPAMP * MCURRENTSENS_CH1_R5_RSHUNT )
311#define MCURRENTSENS_CH2_GAIN_OPAMP 50.0f
312#define MCURRENTSENS_CH2_R8_RSHUNT 0.05f
313#define MCURRENTSENS_CH2_CURRENT_COEFF ( MCURRENTSENS_CH2_GAIN_OPAMP * MCURRENTSENS_CH2_R8_RSHUNT )
314#define MCURRENTSENS_CH1_GAIN 1.0f
315#define MCURRENTSENS_CH1_R16_TOP 1000.0f
316#define MCURRENTSENS_CH1_R21_BOTTOM 38.3f
317#define MCURRENTSENS_CH1_VOLTAGE_COEFF ( MCURRENTSENS_CH1_GAIN * \
318 ( MCURRENTSENS_CH1_R21_BOTTOM / \
319 ( MCURRENTSENS_CH1_R16_TOP + MCURRENTSENS_CH1_R21_BOTTOM ) ) )
320#define MCURRENTSENS_CH2_GAIN 0.5f
321#define MCURRENTSENS_CH2_R15_TOP 1000.0f
322#define MCURRENTSENS_CH2_R17_BOTTOM 38.3f
323#define MCURRENTSENS_CH2_VOLTAGE_COEFF ( MCURRENTSENS_CH2_GAIN * \
324 ( MCURRENTSENS_CH2_R17_BOTTOM / \
325 ( MCURRENTSENS_CH2_R15_TOP + MCURRENTSENS_CH2_R17_BOTTOM ) ) )
326#define MCURRENTSENS_TEMPERATURE_OFFSET 80.0f
327#define MCURRENTSENS_TEMPERATURE_COEFF 0.2973f
328#define MCURRENTSENS_VREF_INTERNAL 2.4f
329#define MCURRENTSENS_V_TO_MV 1000.0f
330#define MCURRENTSENS_GAIN_ADC 1.0f
331#define MCURRENTSENS_ADC_FS_CODE 8388608.0f
332#define MCURRENTSENS_SAMPLE_COUNT 50
333#define MCURRENTSENS_DATA_READY_TIMEOUT_MS 200
334#define MCURRENTSENS_CURRENT_TARGET_0_MA 0.0f
335#define MCURRENTSENS_CURRENT_TARGET_10_MA 10.0f
336#define MCURRENTSENS_VOLTAGE_TARGET_0_MV 0.0f
337#define MCURRENTSENS_VOLTAGE_TARGET_3000_MV 3000.0f
338
343#define MCURRENTSENS_EEPROM_ADDR_START 0x00
344#define MCURRENTSENS_EEPROM_ADDR_END 0xFF
345#define MCURRENTSENS_EEPROM_PAGE_SIZE 16
346
352#define MCURRENTSENS_DEVICE_ADDRESS 0x57
353#define MCURRENTSENS_DEVICE_ADDRESS_WP 0x37
354
363#define MCURRENTSENS_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
364#define MCURRENTSENS_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
365 // mcurrentsens_set
367
372
377
382#define MCURRENTSENS_MAP_MIKROBUS( cfg, mikrobus ) \
383 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
384 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
385 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
386 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
387 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
388 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
389 cfg.clk = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
390 cfg.irq = MIKROBUS( mikrobus, MIKROBUS_INT )
391 // mcurrentsens_map // mcurrentsens
394
399typedef struct
400{
401 int32_t offset_cal;
402 uint32_t gain_cal;
403
405
410typedef struct
411{
412 // Input pins
413 digital_in_t clk;
414 digital_in_t irq;
415
416 // Modules
417 spi_master_t spi;
418 i2c_master_t i2c;
419
420 pin_name_t chip_select;
422
428
430
435typedef struct
436{
437 // Communication gpio pins
438 pin_name_t scl;
439 pin_name_t sda;
440 pin_name_t miso;
441 pin_name_t mosi;
442 pin_name_t sck;
443 pin_name_t cs;
444
445 // Additional gpio pins
446 pin_name_t clk;
447 pin_name_t irq;
448
449 // static variable
450 uint32_t spi_speed;
451 spi_master_mode_t spi_mode;
452 spi_master_chip_select_polarity_t cs_polarity;
453 uint32_t i2c_speed;
454 uint8_t i2c_address;
455
457
468
474
485
500
514
526err_t mcurrentsens_write_reg ( mcurrentsens_t *ctx, uint8_t reg, uint8_t data_in );
527
539err_t mcurrentsens_read_reg ( mcurrentsens_t *ctx, uint8_t reg, uint8_t *data_out );
540
553err_t mcurrentsens_write_regs ( mcurrentsens_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
554
567err_t mcurrentsens_read_regs ( mcurrentsens_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
568
580err_t mcurrentsens_write_reg16 ( mcurrentsens_t *ctx, uint8_t reg, uint16_t data_in );
581
593err_t mcurrentsens_read_reg16 ( mcurrentsens_t *ctx, uint8_t reg, uint16_t *data_out );
594
606err_t mcurrentsens_write_reg24 ( mcurrentsens_t *ctx, uint8_t reg, uint32_t data_in );
607
619err_t mcurrentsens_read_reg24 ( mcurrentsens_t *ctx, uint8_t reg, uint32_t *data_out );
620
631err_t mcurrentsens_send_fast_cmd ( mcurrentsens_t *ctx, uint8_t cmd );
632
643
655err_t mcurrentsens_set_mux ( mcurrentsens_t *ctx, uint8_t vin_p, uint8_t vin_n );
656
667err_t mcurrentsens_set_gain ( mcurrentsens_t *ctx, uint8_t gain );
668
679err_t mcurrentsens_set_osr ( mcurrentsens_t *ctx, uint8_t osr );
680
691err_t mcurrentsens_set_mode ( mcurrentsens_t *ctx, uint8_t mode );
692
703err_t mcurrentsens_get_irq ( mcurrentsens_t *ctx, uint8_t *data_out );
704
715err_t mcurrentsens_set_offset_cal ( mcurrentsens_t *ctx, int32_t data_in );
716
727err_t mcurrentsens_get_offset_cal ( mcurrentsens_t *ctx, int32_t *data_out );
728
739err_t mcurrentsens_set_gain_cal ( mcurrentsens_t *ctx, uint32_t data_in );
740
751err_t mcurrentsens_get_gain_cal ( mcurrentsens_t *ctx, uint32_t *data_out );
752
764err_t mcurrentsens_en_dig_cal ( mcurrentsens_t *ctx, uint8_t en_offset, uint8_t en_gain );
765
777
788
799err_t mcurrentsens_read_adc ( mcurrentsens_t *ctx, int32_t *data_out );
800
812err_t mcurrentsens_read_adc_avg ( mcurrentsens_t *ctx, uint8_t sample_count, int32_t *data_out );
813
825err_t mcurrentsens_read_voltage_avg ( mcurrentsens_t *ctx, uint8_t sample_count, float *data_out );
826
837err_t mcurrentsens_read_ch1_current ( mcurrentsens_t *ctx, float *data_out );
838
849err_t mcurrentsens_read_ch1_voltage ( mcurrentsens_t *ctx, float *data_out );
850
861err_t mcurrentsens_read_ch2_current ( mcurrentsens_t *ctx, float *data_out );
862
873err_t mcurrentsens_read_ch2_voltage ( mcurrentsens_t *ctx, float *data_out );
874
885err_t mcurrentsens_read_temperature ( mcurrentsens_t *ctx, float *data_out );
886
895float mcurrentsens_adc_to_mv ( int32_t adc_code, float gain_adc );
896
910void mcurrentsens_calculate_calib ( mcurrentsens_calib_t *calib, float offset_coeff,
911 float target_1, float measured_1,
912 float target_2, float measured_2 );
913
929err_t mcurrentsens_write_memory ( mcurrentsens_t *ctx, uint8_t address, uint8_t *data_in, uint8_t len );
930
946err_t mcurrentsens_read_memory ( mcurrentsens_t *ctx, uint8_t address, uint8_t *data_out, uint8_t len );
947
958
969
979
989
990#ifdef __cplusplus
991}
992#endif
993#endif // MCURRENTSENS_H
994 // mcurrentsens
996
997// ------------------------------------------------------------------------ END
err_t mcurrentsens_read_adc(mcurrentsens_t *ctx, int32_t *data_out)
mCurrent Sens read ADC data function.
void mcurrentsens_cfg_setup(mcurrentsens_cfg_t *cfg)
mCurrent Sens configuration object setup function.
err_t mcurrentsens_read_reg(mcurrentsens_t *ctx, uint8_t reg, uint8_t *data_out)
mCurrent Sens read register function.
err_t mcurrentsens_write_memory(mcurrentsens_t *ctx, uint8_t address, uint8_t *data_in, uint8_t len)
mCurrent Sens write memory function.
err_t mcurrentsens_read_ch1_voltage(mcurrentsens_t *ctx, float *data_out)
mCurrent Sens read channel 1 voltage function.
err_t mcurrentsens_write_reg16(mcurrentsens_t *ctx, uint8_t reg, uint16_t data_in)
mCurrent Sens write 16-bit register function.
err_t mcurrentsens_set_gain(mcurrentsens_t *ctx, uint8_t gain)
mCurrent Sens set gain function.
err_t mcurrentsens_read_temperature(mcurrentsens_t *ctx, float *data_out)
mCurrent Sens read temperature function.
err_t mcurrentsens_send_fast_cmd(mcurrentsens_t *ctx, uint8_t cmd)
mCurrent Sens send fast command function.
err_t mcurrentsens_write_reg(mcurrentsens_t *ctx, uint8_t reg, uint8_t data_in)
mCurrent Sens write register function.
void mcurrentsens_calculate_calib(mcurrentsens_calib_t *calib, float offset_coeff, float target_1, float measured_1, float target_2, float measured_2)
mCurrent Sens calculate calibration function.
uint8_t mcurrentsens_get_irq_pin(mcurrentsens_t *ctx)
mCurrent Sens get IRQ pin function.
err_t mcurrentsens_get_offset_cal(mcurrentsens_t *ctx, int32_t *data_out)
mCurrent Sens get offset calibration function.
err_t mcurrentsens_set_offset_cal(mcurrentsens_t *ctx, int32_t data_in)
mCurrent Sens set offset calibration function.
err_t mcurrentsens_default_cfg(mcurrentsens_t *ctx)
mCurrent Sens default configuration function.
err_t mcurrentsens_write_reg24(mcurrentsens_t *ctx, uint8_t reg, uint32_t data_in)
mCurrent Sens write 24-bit register function.
err_t mcurrentsens_read_ch2_current(mcurrentsens_t *ctx, float *data_out)
mCurrent Sens read channel 2 current function.
err_t mcurrentsens_read_adc_avg(mcurrentsens_t *ctx, uint8_t sample_count, int32_t *data_out)
mCurrent Sens read averaged ADC function.
err_t mcurrentsens_fetch_calib(mcurrentsens_t *ctx)
mCurrent Sens fetch calibration function.
err_t mcurrentsens_init(mcurrentsens_t *ctx, mcurrentsens_cfg_t *cfg)
mCurrent Sens initialization function.
uint8_t mcurrentsens_get_clk_pin(mcurrentsens_t *ctx)
mCurrent Sens get CLK pin function.
err_t mcurrentsens_read_memory(mcurrentsens_t *ctx, uint8_t address, uint8_t *data_out, uint8_t len)
mCurrent Sens read memory function.
err_t mcurrentsens_write_regs(mcurrentsens_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
mCurrent Sens write multiple registers function.
err_t mcurrentsens_check_com(mcurrentsens_t *ctx)
mCurrent Sens communication check function.
err_t mcurrentsens_read_reg24(mcurrentsens_t *ctx, uint8_t reg, uint32_t *data_out)
mCurrent Sens read 24-bit register function.
err_t mcurrentsens_apply_calib(mcurrentsens_t *ctx, mcurrentsens_calib_t cal)
mCurrent Sens apply channel calibration function.
err_t mcurrentsens_get_irq(mcurrentsens_t *ctx, uint8_t *data_out)
mCurrent Sens get IRQ function.
err_t mcurrentsens_set_mux(mcurrentsens_t *ctx, uint8_t vin_p, uint8_t vin_n)
mCurrent Sens set MUX function.
err_t mcurrentsens_read_reg16(mcurrentsens_t *ctx, uint8_t reg, uint16_t *data_out)
mCurrent Sens read 16-bit register function.
err_t mcurrentsens_set_osr(mcurrentsens_t *ctx, uint8_t osr)
mCurrent Sens set OSR function.
err_t mcurrentsens_en_dig_cal(mcurrentsens_t *ctx, uint8_t en_offset, uint8_t en_gain)
mCurrent Sens enable digital calibration function.
err_t mcurrentsens_wait_data_ready(mcurrentsens_t *ctx)
mCurrent Sens wait data ready function.
err_t mcurrentsens_read_voltage_avg(mcurrentsens_t *ctx, uint8_t sample_count, float *data_out)
mCurrent Sens read averaged voltage function.
float mcurrentsens_adc_to_mv(int32_t adc_code, float gain_adc)
mCurrent Sens convert ADC code to millivolts function.
err_t mcurrentsens_store_calib(mcurrentsens_t *ctx)
mCurrent Sens store calibration function.
err_t mcurrentsens_get_gain_cal(mcurrentsens_t *ctx, uint32_t *data_out)
mCurrent Sens get gain calibration function.
err_t mcurrentsens_set_mode(mcurrentsens_t *ctx, uint8_t mode)
mCurrent Sens set mode function.
err_t mcurrentsens_set_gain_cal(mcurrentsens_t *ctx, uint32_t data_in)
mCurrent Sens set gain calibration function.
err_t mcurrentsens_read_ch2_voltage(mcurrentsens_t *ctx, float *data_out)
mCurrent Sens read channel 2 voltage function.
err_t mcurrentsens_read_ch1_current(mcurrentsens_t *ctx, float *data_out)
mCurrent Sens read channel 1 current function.
err_t mcurrentsens_read_regs(mcurrentsens_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
mCurrent Sens read multiple registers function.
mcurrentsens_return_value_t
mCurrent Sens Click return value data.
Definition mcurrentsens.h:463
@ MCURRENTSENS_OK
Definition mcurrentsens.h:464
@ MCURRENTSENS_ERROR
Definition mcurrentsens.h:465
This file contains SPI specific macros, functions, etc.
mCurrent Sens calibration data structure.
Definition mcurrentsens.h:400
uint32_t gain_cal
Definition mcurrentsens.h:402
int32_t offset_cal
Definition mcurrentsens.h:401
mCurrent Sens Click configuration object.
Definition mcurrentsens.h:436
pin_name_t clk
Definition mcurrentsens.h:446
uint32_t i2c_speed
Definition mcurrentsens.h:453
pin_name_t irq
Definition mcurrentsens.h:447
spi_master_chip_select_polarity_t cs_polarity
Definition mcurrentsens.h:452
pin_name_t sck
Definition mcurrentsens.h:442
spi_master_mode_t spi_mode
Definition mcurrentsens.h:451
pin_name_t mosi
Definition mcurrentsens.h:441
uint32_t spi_speed
Definition mcurrentsens.h:450
pin_name_t scl
Definition mcurrentsens.h:438
pin_name_t miso
Definition mcurrentsens.h:440
pin_name_t sda
Definition mcurrentsens.h:439
pin_name_t cs
Definition mcurrentsens.h:443
uint8_t i2c_address
Definition mcurrentsens.h:454
mCurrent Sens Click context object.
Definition mcurrentsens.h:411
bool calibrated
Definition mcurrentsens.h:427
spi_master_t spi
Definition mcurrentsens.h:417
mcurrentsens_calib_t ch2_curr_cal
Definition mcurrentsens.h:425
mcurrentsens_calib_t ch1_curr_cal
Definition mcurrentsens.h:423
digital_in_t irq
Definition mcurrentsens.h:414
i2c_master_t i2c
Definition mcurrentsens.h:418
mcurrentsens_calib_t ch1_volt_cal
Definition mcurrentsens.h:424
mcurrentsens_calib_t ch2_volt_cal
Definition mcurrentsens.h:426
uint8_t slave_address
Definition mcurrentsens.h:421
pin_name_t chip_select
Definition mcurrentsens.h:420
digital_in_t clk
Definition mcurrentsens.h:413